package filter;

import jakarta.servlet.*;

import java.io.IOException;

public class EncodingFinter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    //clain:链
    /**
     * 1.过滤器中的所有代码，在过滤特点请求的时候都会执行
     * 2。必要的时候让过滤器继续
     */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("utf-8");
        servletResponse.setCharacterEncoding("utf-8");
        servletResponse.setContentType("text/html;charset=UTF-8");
        System.out.println("执行前");
        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("执行后");
    }

    @Override
    public void destroy() {
        System.out.println("销毁");

    }
}
